<%@page import="messages.SystemMessage"%>
<%@page import="data.Succursale"%>
<%@page import="java.util.ArrayList"%>
<%@page import="controlleur.succursaleControlleur"%>
<%
	String titre = "Ajouter succursale";
	Succursale succursale = new Succursale();
	//recuperer la succursale
	if(!request.getParameter(SystemMessage.SUCCURSALE_ID).isEmpty())
	{
		if(request.getParameter(SystemMessage.SUCCURSALE_ID).equals("-1"))
		{				
			succursale.setId(-1);
			succursale.setNom("");
			succursale.setDescription("");
			succursale.setAdresse("");
			succursale.setCodePostal("");
			
		}
	}
	
%>
<jsp:include page="../part/header.jsp" />	

<script>

$(function() {

	$("#callAjax").click(function() {
	var vnom = $.trim($("#nom").val());
	var vdesc = $.trim($("#desc").val());
	var vadr = $.trim($("#adresse").val());
	var vcp = $.trim($("#cpostal").val());
	var vid = $.trim($("#idSuccursale").val());
	var vdetid = $.trim($("#idDetaillant").val());
	
		if(validate()){			
			$.ajax({
			type: "GET",
			url: "<%= request.getContextPath() %>/ajax/saveSuccursaleAjax.jsp",
			data: ({nom: vnom,desc: vdesc,adr: vadr,cp: vcp,id: vid,idDet: vdetid}),
			cache: false,
			dataType: "text",
			success: onSuccess
			});			
		}
	});
	
		$("#resultLog").ajaxError(function(event, request, settings, exception) {
		$("#resultLog").html("Error Calling: " + settings.url + "<br />HTPP Code: " + request.status);
	});

	function onSuccess(data)
	{
		$("#resultLog").html("Result: " + data);
		//$.mobile.changePage( "listeSuccursales.jsp", { transition: "flip"} );
		window.location.href = "listSuccursales.jsp";
	}
	function validate()
	{
		return true;
	}
});



</script>



 <form id="editSucc">
	<div data-role="header" data-position="inline">
		<a href="javascript: history.go(-1)" data-icon="delete">Annuler</a>
		<h1><%=titre %></h1>			
		<a onclick="$('form#editSucc').trigger('submit')" data-role="button" data-icon="check" id="callAjax">Sauvegarder</a>
	</div>
	
	
	 <div data-role="content">
           
         <div data-role="fieldcontain">
               <label for="nom">Nom</label>
               <input type="text" name="nom" id="nom" value="" />

               <label for="desc">Description</label>
               <input type="text" name="desc" id="desc" value="" />
               
               <label for="adresse">Adresse</label>
               <input type="text" name="adresse" id="adresse" value="" />
               
               <label for="cpostal">CodePostal</label>
               <input type="text" name="cpostal" id="cpostal" value="" />
               
                               
           </div>
            
     </div>
     <input type="hidden" name="idDetaillant" id="idDetaillant" value="<%=session.getAttribute(SystemMessage.DETAILLANT_ID) %>" />
     <input type="hidden" name="idSuccursale" id="idSuccursale" value="<%=request.getParameter(SystemMessage.SUCCURSALE_ID) %>" />
</form>

<div id="resultLog">Rien</div> 



<jsp:include page="../part/footer.jsp" />	